package com.example.netactivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class ItemAdapter extends ArrayAdapter {
    private static final String TAG = "MyAdapter";
    public ItemAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Item> list) {
        super(context, resource, list);
    }

    @NonNull
    @Override
    public View getView(int position,@NonNull View convertView,@NonNull ViewGroup parent){
        //return super.getView(position,convertView,parent);
        View itemView = convertView;
        if(itemView == null){
            itemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item,parent,false);
        }
        Item item = (Item) getItem(position);
        TextView title = (TextView) itemView.findViewById(R.id.itemTitle);
        TextView price = (TextView) itemView.findViewById(R.id.price);

        title.setText("币种:"+ item.getCname());
        price.setText("价格:"+ item.getPrice());

        return itemView;
    }
}
